<template>
  <view>
    <view
      class="data-item flex-row align-center"
      v-for="(item, index) in list"
      :key="index"
      @click="toDetail(item)"
    >
      <!--  标题 -->
      <view class="name">
        <view class="title">{{ item['name'] }}</view>
        <view class="flex-row align-center">
          <image
            class="tag"
            :src="`/static/images/icons/${item.marketCode}.png`"
            mode=""
          ></image>
          <text class="text-sm">{{ item['code'] }}</text>
        </view>
      </view>

      <!--  最新价 -->
      <view
        class="price"
        :class="item['changepercent'] > 0 ? 'text-red' : 'text-green'"
      >
        {{ item['trade'] }}
      </view>

      <!-- 涨幅 -->
      <view
        class="up-down"
        :class="item['changepercent'] > 0 ? 'text-red' : 'text-green'"
      >
        {{ item['changepercent'] }}%
      </view>
    </view>
  </view>
</template>

<script setup>
  defineOptions({
    name: 'RTList',
  });

  const props = defineProps({
    list: {
      type: Array,
      default: () => [],
    },
  });

  const toDetail = (item) => {
    uni.navigateTo({
      url: '/pages/shares/detail?code=' + item.symbol,
    });
  };
</script>

<style lang="scss" scoped>
  .data-item {
    height: 128rpx;
    border-bottom: 2rpx solid #e2e2e2;
    padding: 12px 12px 12px 0;

    // 标题
    .name {
      font-family: PingFangSC, PingFang SC;
      font-weight: 400;
      font-size: 32rpx;
      color: #1e1e1e;
      text-align: left;
      font-style: normal;

      .title {
        margin-bottom: 8rpx;
      }

      .tag {
        width: 26.96rpx;
        height: 28rpx;
        margin-right: 10rpx;
      }

      .text-sm {
        font-size: 24rpx;
        color: #454545;
        font-style: normal;
      }
    }

    // price
    .price {
      font-family: DINAlternate, DINAlternate;
      font-weight: bold;
      font-size: 24rpx;
      color: #f74e51;
      text-align: center;
      font-style: normal;
    }
    .text-green {
      color: #2ba039;
    }
    .text-red {
      color: #f74e51;
    }

    // 涨幅
    .up-down {
      font-family: DINAlternate, DINAlternate;
      font-weight: bold;
      font-size: 24rpx;
      text-align: right;
      font-style: normal;
    }
  }
  .head {
  }

  .name,
  .price,
  .up-down {
    box-sizing: border-box;
  }

  .name {
    width: 50%;
  }

  .price,
  .up-down {
    width: 25%;
  }
</style>
